package com.mydubbo.loadbalance;

import java.util.List;
import java.util.Random;

import com.mydubbo.util.Log;

public class RandomLoadBalance implements LoadBalance {

	@Override
	public String select(List<String> addresses) {
		Log.log("正在进行负载均衡选择服务器");
		Random random = new Random();
		int index = random.nextInt(addresses.size());
		String address = addresses.get(index);
		Log.log("选择的服务器是=》" + address);
		return address;
	}

	public static void main(String[] args) {
		Random random = new Random();
		for(int i=0;i<10;i++) {
			int index = random.nextInt(5);
			System.out.println(index);
		}
	}
}
